package com.sh1604.duitang.activity;

import android.content.Context;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.widget.ListView;

import com.google.gson.Gson;
import com.sh1604.duitang.R;
import com.sh1604.duitang.adapter.AtricleAdapter;
import com.sh1604.duitang.constant.UrlString;
import com.sh1604.duitang.mybean.AtricleBean;
import com.sh1604.duitang.utils.OKHttpUtils;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class AtricleActivity extends AppCompatActivity {

    private ListView listView;
    private List<AtricleBean.DataBean.ObjectListBean> mDatas;
    private AtricleAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_atricle);

        mDatas = new ArrayList<>();
        listView = (ListView) findViewById(R.id.atricle);
        adapter = new AtricleAdapter(this,mDatas);
        listView.setAdapter(adapter);
        OKHttpUtils.newInstance(this).getAsyncMainData(UrlString.URL_Atricle, new OKHttpUtils.MyCallBack() {
            @Override
            public void onFailure(IOException e) {

            }

            @Override
            public void onResponse(String result) {
                AtricleBean bean = new Gson().fromJson(result,AtricleBean.class);
                mDatas.addAll(bean.getData().getObject_list());
                Log.i("mData111111s","--->!!!--->!!!--->"+mDatas.size());

                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        adapter.notifyDataSetChanged();
                    }
                });
            }
        });
    }
}
